package com.eascs.web.o2o.scheduler.quartz;


import javax.inject.Inject;

import org.springframework.stereotype.Component;

import com.alibaba.dubbo.config.annotation.Reference;
import com.eascs.admin.common.service.IArchiveService;
import com.eascs.admin.common.service.ICreditArchiveService;
import com.eascs.admin.common.vo.ModelResult;
import com.eascs.app.log.Logger;
import com.eascs.app.log.LoggerFactory;
import com.eascs.common.util.StopWatch;
import com.eascs.web.o2o.quartz.util.BaseJobUtil;
import com.eascs.web.o2o.quartz.util.ExecutorService;
import com.eascs.web.o2o.scheduler.service.SynchroAfterLoanForService;
import com.eascs.web.o2o.scheduler.service.SynchroService;
import com.eascs.web.o2o.scheduler.service.SynoInfoAssetStructureService;

/**
 * admin：与admin相关的定时任务，并且数据落库在admin中
 */
@Component("AdminSynchroQuartz")
public class AdminSynchroQuartz extends BaseJobUtil {
	protected final Logger logger = LoggerFactory.getLogger(getClass());

	@Reference
	IArchiveService iArchiveService;
	@Reference
	ICreditArchiveService creditArchiveService;
	@Inject
	SynchroAfterLoanForService synchroAfterLoanForService;
	@Inject
	SynoInfoAssetStructureService synoInfoAssetStructureService;
	@Inject
	SynchroService synchroService;

	


	public void saveO2oPlatformRegional() {
		executor("AdminSynchroQuartz", "saveO2oPlatformRegional", "用户中心平台大区数据", new ExecutorService() {
			@Override
			public void exe() {
				synchroService.saveO2oPlatformRegional2();
			}
		});
	}

	public void archive() {
		executor("AdminSynchroQuartz", "archive", "归档", new ExecutorService() {
			@Override
			public void exe() {
				 iArchiveService.buildArchiveExport();
			}
		});
	}

	public void creditArchive() {
		executor("AdminSynchroQuartz", "creditArchive", "征信归档", new ExecutorService() {
			@Override
			public void exe() {
				creditArchiveService.startup();
			}
		});
	}

	public void onFile() {
		executor("AdminSynchroQuartz", "onFile", "数据归档", new ExecutorService() {
			@Override
			public void exe() {
				ModelResult<Boolean> result = iArchiveService.startUpPlaceOnFile();
				boolean flag = result.getModel();
				StopWatch time = new StopWatch();
				if (flag) {
					logger.info("[admin] [数据归档]任务[完成]，共耗时：[{}]分", time);
				} else {
					logger.info("[admin] [数据归档]任务[失败]，共耗时：[{}]分", time);
				}
			}
		});
	}

	public void syncForService() {
		executor("AdminSynchroQuartz", "syncForService", "放款余额,上年年末余额，第一次放款时间,续贷", new ExecutorService() {
			@Override
			public void exe() {
				StopWatch s = new StopWatch();
				logger.info("同步放款余额到service开始");
				synchroAfterLoanForService.synchroAfterLoanForBillCode();
				logger.info("同步放款余额到service结束，耗时：[{}]秒", s.elapsedTime() / 1000);
				StopWatch s1 = new StopWatch();
				logger.info("同步放款次数，第一次放款时间到service开始");
				synchroAfterLoanForService.synchroAfterLoanForCustomer();
				logger.info("同步放款次数，第一次放款时间到service结束，耗时：[{}]秒", s1.elapsedTime() / 1000);
				StopWatch s3 = new StopWatch();
				logger.info("开始同步续贷字段");
				synchroAfterLoanForService.synchReLoan();
				logger.info("结束同步续贷字段，耗时：[{}]秒", s3.elapsedTime() / 1000);
			}
		});
	}

	public void synchBalanceHisTask() {
		executor("AdminSynchroQuartz", "synchBalanceHisTask", "同步余额数据，历史存档", new ExecutorService() {
			@Override
			public void exe() {
				synchroAfterLoanForService.synchBalanceHis();
			}
		});
	}

	public void saveServiceJob() {
		executor("AdminSynchroQuartz", "saveServiceJob", "将oa中的数据字典同步到admin", new ExecutorService() {
			@Override
			public void exe() {
				synchroService.saveData();
			}
		});
	}

	public void updateCreditStatus() {
		executor("AdminSynchroQuartz", "updateCreditStatus", "更新征信归档状态", new ExecutorService() {
			@Override
			public void exe() {
				synchroService.updateCreditStatus();
			}
		});
	}

	public void creditManagerRankReport() {
		executor("AdminSynchroQuartz", "creditManagerRankReport", "省区和信贷经理的关联关系", new ExecutorService() {
			@Override
			public void exe() {
				synchroService.loadWToS();
			}
		});
	}

	public void saveAssetStructurePrincipalDaily() {
		executor("AdminSynchroQuartz", "saveAssetStructurePrincipalDaily", "保存资产结构本金日报表数据", new ExecutorService() {
			@Override
			public void exe() {
				synoInfoAssetStructureService.saveAssetStructurePrincipalDaily();
			}
		});
	}
	
	
/*	public void synchcancelLoanapply() {
		executor("AdminSynchroQuartz", "synchcancelLoanapply", "贷款申请超时作废", new ExecutorService() {
			@Override
			public void exe() {
				synchroService.cancelLoanapply();
			}
		});
	}*/

}
